<?php $this->load->view('intro'); ?>
<body id="category_relation">
<?php $this->load->view('admin/navigation'); ?>
<div id="edit_section">
<label>Food Category: </label>
<select name="food_category_id" id="food_category_group" onkeyup="change_food_category()" onchange="change_food_category()">
<?php foreach($food_category as $option_category): ?>
<option
<?php if($food_select == $option_category['id']) echo "selected=\"selected\""; ?>
value="<?=$option_category['id']?>"><?=$option_category['en_name']?></option>
<?php endforeach; ?>
</select>
    
<label>Food Option Category: </label>
<select name="food_optoin_category_id" id="food_option_category_group" onkeyup="change_food_option_category()"
        onchange="change_food_option_category()">
<option <?php if($opt_select === -1) echo "selected=\"selected\""; ?> value="-1">no relation</option>
<?php foreach($food_option_category as $option_category): ?>
<option
<?php if($opt_select == $option_category['id']) echo "selected=\"selected\""; ?>
value="<?=$option_category['id']?>"><?=$option_category['en_name']?></option>
<?php endforeach; ?>
</select>
</div>

<form method="post" id="helper_form" action="index.php/admin/category_relation">
    <input name="food_select" id="food_select" type="hidden" value="" />
</form>

<script type="text/javascript">

function change_food_category()
{
    var $food_select = $("#food_category_group").val();
    $("#food_select").val($food_select);
    $("#helper_form").submit();
}

function change_food_option_category()
{
    var $food_category_id = $("#food_category_group").val();
    var $option_category_id = $("#food_option_category_group").val();
    $data = {food_category_id:  $food_category_id, option_category_id: $option_category_id};
      $.ajax({
        type: "POST",
        url: "index.php/admin/category_relation/change_relation",
        dataType: "json",
        data: $data,
        success: function(msg){
            //donothing
        }
      });
}

</script>

<?php $this->load->view('outro'); ?>